<template>
  <div id="base-list" >
      <lb-table
          :column="baseColumns"
          :data="baseList"
          pagination
          :total="page.totalNum"
          layout="total, sizes, prev, pager, next, jumper"
          :page-sizes="[5, 10, 20, 30, 50]"
          :current-page.sync="page.currentPage"
          :page-size="page.pageSize"
          @selection-change="onMultipleSelection"
          @size-change="handleSizeChange"
          @p-current-change="handleCurrentChange"
      >
      </lb-table>
  </div>
</template>

<script>
import LbTable from '../../../components/lb-table/lb-table'
export default {
  components: { LbTable },
  props: {
    customerId: {
      type: String,
      default: () => "String",
    },
    searchObj: {
      type: Object,
      default: () => {},
    },
    baseColumns: {
      type: Array,
      default: () => [],
    },
    baseList: {
      type: Array,
      default: () => [],
    }
  },
  data () {
    return {
      // list: [],  // 列表
      page: { pageNo: 1, pageSize: 10, totalNum: 0, currentPage: 1 },
      dialog: { visible: false, title: "编辑", type: '' },
      form: {
        name: '', // 公司名称 string
        simpleName: '', // 公司简称 string
        sort: '', // 序号 int
        status: '' // 状态（字典分组：enable_status） int
      },
      rules: {
        customerName: [
          { required: true, message: '请输入跟进人', trigger: 'change' },
        ],
      },
    };
  },
  created () {

  },
  mounted () { },
/*
  watch: {
    baseList: {
      handler (newVal, oldVal) {
        console.log(newVal, oldVal)
      },
      deep: true,
    },
  },
  */
  methods: {
    fetchData (name) {
      console.log(name)
      // if(this.count > 0){return} // 限制多次重复请求
      let getDataFun
      const type = name ? name : this.currentType.name
      switch (type) {
          // 获取消费记录
        case "consumption":
          // this.column = columnConsumption
          getDataFun = this.$api.customerOrderPageList
          this.getCustomerOrderStatistics() // 消费记录-统计信息查询接口
          break;
          // 分配记录
        case "allocation":
          // this.column = columnAllocation
          getDataFun = this.$api.customerAllocationList
          break;
          // 跟进记录
        case "followUp":
          // this.column = columnFollowUp
          getDataFun = this.$api.customerTrackingPageList
          break;
          // 客户记录
        case "record":
          // this.column = columnRecord
          getDataFun = this.$api.customerHistoryPageList
          break;
          // 标签/人群
        default:
          // console.log("标签/人群")
          // console.log("客户详情")
      }
      if (getDataFun) {
        let params = {
          id: this.customerId,
          pageNo: this.page.pageNo,
          pageSize: this.page.pageSize

        }
        if (this.currentType.name === "allocation") {
          params = {
            request:
                {
                  customerId: this.customerId,
                  pageNo: this.page.pageNo,
                  pageSize: this.page.pageSize
                },

            version: ""
          }
        }
        getDataFun(params).then((res) => {
          // this.list = res.data.list
          res.data.list.forEach(res => {
            res.receiveState = this.tractringData.find((e) => e.dictId == res.receiveState).dictName
            res.wxFencing = this.tractringData.find((e) => e.dictId == res.wxFencing).dictName

          });
          // this.list = res.data.list
          this.page.totalNum = res.data.totalNum
          this.count++
        }).catch((err) => {
          console.log(err)
        })
      }
    },
    handleCurrentChange (currentChange) {
      this.page.pageNo = currentChange
      this.fetchData()
    },
    handleSizeChange (sizeChange) {
      this.page.pageSize = sizeChange
      this.fetchData()
    },
    onMultipleSelection (val) {
      this.$emit("onMultipleSelection", val) // 向外传值
    },
    // 显示  dialog
    showDialog (title, type, row) {
      console.log(title, type, row)
      this.dialog.visible = true;
      this.dialog.title = title;
      // this.dialog.type = type
      // this.currentRow = row
      this.form = {
        name: '', // 公司名称 string
        simpleName: '', // 公司简称 string
        sort: '', // 序号 int
        status: '' // 状态（字典分组：enable_status） int
      }
    },
  },
};
</script>
<style lang="scss">

//#base-list{
// .el-image{
//   width: 160px;
//   height: 120px;
//   img{
//     width: 100%;
//     object-fit: cover;
//   }
// }
//}

</style>
